<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Model\RoomPercentageModel;
use Illuminate\Http\Request;

class RoomController extends Controller{

    public function index(){
        $room_data = RoomPercentageModel::where('id',1)->first();

        $data['num'] = 0;
        if($room_data->percentage >= 0){
           $data = [
               'num'=>$room_data->percentage
           ];
        }
        return view('Admin/room',$data);
    }

    public function save($num){
        if(!ebsig_is_int($num,2)){
            return response()->json(array(
                'code' => 400,
                'message' => '请输入有效数字'
            ));
        }

        if($num > 100){
            return response()->json(array(
                'code' => 400,
                'message' => '请输入小于100的数字'
            ));
        }

        if(RoomPercentageModel::where('id',1)->update(['percentage'=>$num])){
            return response()->json(array(
                'code' => 200,
                'message' => '操作成功'
            ));
        };
    }
}